package com.ping.model;

import java.util.List;

import com.eaio.uuid.UUID;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class Brand extends BaseModel<Brand>{
	public static final String uuid = "uuid";
	public static final String name = "name";
	public static final String preletter = "preletter";
	public static final String hot = "hot";
	public static final String cat = "cat";
	public static final String tlevel = "tlevel";
	public static final String blevel = "blevel";
	
	public static final Brand dao = new Brand();
	
	public static List<Record> findHotBrands(){
		String sql = "SELECT * FROM monkey_brand WHERE hot=1 ORDER BY blevel";
		return Db.find(sql);
	}
	
	/**
	 * order=1: ORDER BY preletter, blevel
	 * order=2: ORDER BY tlevel, blevel
	 * else: ORDER BY blevel
	 * @return
	 */
	public static List<Record> findBrandsExceptHot(int order){
		String sql = null;

		switch (order) {
		case 1:
			sql = "SELECT * FROM monkey_brand WHERE hot!=1 ORDER BY preletter, blevel";
			break;
			
		case 2:
			sql = "SELECT * FROM monkey_brand WHERE hot!=1 ORDER BY tlevel, blevel";
			
		default:
			sql = "SELECT cat FROM monkey_brand WHERE hot!=1 ORDER BY tlevel";
			break;
		}
		
		return Db.find(sql);
	}
	
	public static List<Record> findBrandsByCat(String cat){
		String sql = "SELECT * FROM monkey_brand WHERE cat=? ORDER BY blevel";
		return Db.find(sql, cat);
	}
	
	public static List<Record> findCats(){
		String sql = "SELECT cat FROM monkey_brand GROUP BY cat order by tlevel";
		List<Record> cats = Db.find(sql);
		return cats;
	}
}
